﻿namespace CommonLibrary.Models
{
    using BLToolkit.DataAccess;
    using BLToolkit.Mapping;
    using System;
    using System.Collections.Generic;

    #region 基础数据

    [TableName(Owner = "public", Name = "sys_Application")]
    public partial class sys_Application
    {
        [PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String AppguId { get; set; } // character varying(50)(50)
        public String AppName { get; set; } // character varying(50)(50)

        // sys_Module_AppId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "AppId", CanBeNull = true)]
        public IEnumerable<sys_Module> sys_Modules { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Menu")]
    public partial class sys_Menu
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public Int32 ModuleId { get; set; } // integer
        public String Name { get; set; } // character varying(50)(50)
        public String Url { get; set; } // character varying(250)(250)
        [Nullable]
        public Int32? ParentMenuId { get; set; } // integer

        // sys_Menu_ModuleId_fkey
        [Association(ThisKey = "ModuleId", OtherKey = "Id", CanBeNull = false)]
        public sys_Module sys_Module { get; set; }

        [Association(ThisKey = "MenuId", OtherKey = "Id", CanBeNull = true)]
        public sys_RoleMenu sys_RoleMenu { get; set; }
        
        // sys_RoleMenu_MenuId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "MenuId", CanBeNull = true)]
        public IEnumerable<sys_RoleMenu> ChildrenMenus { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Module")]
    public partial class sys_Module
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public Int32 AppId { get; set; } // integer
        public String Name { get; set; } // character varying(50)(50)
        public String Url { get; set; } // character varying(250)(250)

        // sys_Module_AppId_fkey
        [Association(ThisKey = "AppId", OtherKey = "Id", CanBeNull = false)]
        public sys_Application sys_Application { get; set; }

        // sys_Menu_ModuleId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "ModuleId", CanBeNull = true)]
        public IEnumerable<sys_Menu> sys_Menus { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Org")]
    public partial class sys_Org
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String Name { get; set; } // character varying(50)(50)
        [Nullable]
        public Int32? ParentOrgId { get; set; } // integer
        [NonUpdatable]
        public Int32 State { get; set; }

        // sys_Org_ParentOrgId_fkey
        [Association(ThisKey = "ParentOrgId", OtherKey = "Id", CanBeNull = true)]
        public sys_Org ParentOrg { get; set; }

        // sys_Org_ParentOrgId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "ParentOrgId", CanBeNull = true)]
        public IEnumerable<sys_Org> ChildrenOrgs { get; set; }

        // sys_UserOrgPosition_OrgId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "OrgId", CanBeNull = true)]
        public IEnumerable<sys_UserOrgPosition> sys_UserOrgPositions { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Permission")]
    public partial class sys_Permission
    {
        [PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String Name { get; set; } // character varying(20)(20)

        // sys_RolePermission_PermissionId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "PermissionId", CanBeNull = true)]
        public IEnumerable<sys_RolePermission> sys_RolePermissions { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Position")]
    public partial class sys_Position
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String Name { get; set; } // character varying(50)(50)

        // sys_UserOrgPosition_PositionId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "PositionId", CanBeNull = true)]
        public IEnumerable<sys_UserOrgPosition> sys_UserOrgPositions { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Role")]
    public partial class sys_Role
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String Name { get; set; } // character varying(20)(20)

        // sys_RolePermission_RoleId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "RoleId", CanBeNull = true)]
        public sys_RolePermission sys_RolePermission { get; set; }

        // sys_UserRole_RoleId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "RoleId", CanBeNull = true)]
        public IEnumerable<sys_UserRole> sys_UserRoles { get; set; }

        // sys_RoleMenu_RoleId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "RoleId", CanBeNull = true)]
        public sys_RoleMenu sys_RoleMenu { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_User")]
    public partial class sys_User
    {
        [Identity, PrimaryKey(1)]
        public Int32 Id { get; set; } // integer
        public String LoginName { get; set; } // character varying(20)(20)
        public String Password { get; set; } // character varying(200)(200)
        public String Salt { get; set; } // character varying(20)(20)
        public String LastIPAddress { get; set; } // character varying(50)(50)
        [Nullable]
        public DateTime? LastLoginTime { get; set; } // timestamp with time zone    
        [NonUpdatable]
        public DateTime CreationTime { get; set; } // timestamp with time zone
        [NonUpdatable]
        public DateTime UpdatedTime { get; set; } // timestamp with time zone
        [NonUpdatable]
        public int State { get; set; }

        // sys_Userinfo_UserId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "UserId", CanBeNull = true)]
        public sys_UserInfo sys_UserInfo { get; set; }

        // sys_UserOrgPosition_UserId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "UserId", CanBeNull = true)]
        public IEnumerable<sys_UserOrgPosition> sys_UserOrgPositions { get; set; }
        
        // sys_UserRole_UserId_fkey_BackReference
        [Association(ThisKey = "Id", OtherKey = "UserId", CanBeNull = true)]
        public sys_UserRole sys_UserRole { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_Userinfo")]
    public partial class sys_UserInfo
    {
        [PrimaryKey(1)]
        public Int32 UserId { get; set; } // integer
        public String UserName { get; set; } // character varying(100)(100)
        public String Sex { get; set; } // character varying(10)(10)
        public String WorkEmail { get; set; } // character varying(200)(200)
        public String Mobile { get; set; } // character varying(20)(20)
        public String IDCard { get; set; } // character varying(50)(50)
        public String Tel { get; set; } // character varying(20)(20)
        [Nullable]
        public DateTime? Birthday { get; set; } // timestamp with time zone
        public String OtherEmail { get; set; } // character varying(200)(200)

        // sys_Userinfo_UserId_fkey
        [Association(ThisKey = "UserId", OtherKey = "Id", CanBeNull = false)]
        public sys_User sys_User { get; set; }
    }

    #endregion
    
    #region 关联关系
    [TableName(Owner = "public", Name = "sys_UserOrgPosition")]
    public partial class sys_UserOrgPosition
    {
        [PrimaryKey(1)]
        public Int32 UserId { get; set; } // integer
        [PrimaryKey(2)]
        public Int32 PositionId { get; set; } // integer
        [PrimaryKey(3)]
        public Int32 OrgId { get; set; } // integer
        [Nullable]
        public Int32? ParentUserId { get; set; } // integer

        // sys_UserOrgPosition_UserId_fkey
        [Association(ThisKey = "UserId", OtherKey = "Id", CanBeNull = false)]
        public sys_User sys_User { get; set; }

        // sys_UserOrgPosition_PositionId_fkey
        [Association(ThisKey = "PositionId", OtherKey = "Id", CanBeNull = false)]
        public sys_Position sys_Position { get; set; }

        // sys_UserOrgPosition_OrgId_fkey
        [Association(ThisKey = "OrgId", OtherKey = "Id", CanBeNull = false)]
        public sys_Org sys_Org { get; set; }

        // sys_UserOrgPosition_ParentUserId_fkey
        [Association(ThisKey = "ParentUserId", OtherKey = "Id", CanBeNull = true)]
        public sys_User ParentUser { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_UserRole")]
    public partial class sys_UserRole
    {
        [PrimaryKey(1)]
        public Int32 UserId { get; set; } // integer
        [PrimaryKey(2)]
        public Int32 RoleId { get; set; } // integer

        // sys_UserRole_UserId_fkey
        [Association(ThisKey = "UserId", OtherKey = "Id", CanBeNull = false)]
        public sys_User sys_User { get; set; }

        // sys_UserRole_RoleId_fkey
        [Association(ThisKey = "RoleId", OtherKey = "Id", CanBeNull = false)]
        public sys_Role sys_Role { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_RoleMenu")]
    public partial class sys_RoleMenu
    {
        [PrimaryKey(1)]
        public Int32 RoleId { get; set; } // integer
        [PrimaryKey(2)]
        public Int32 MenuId { get; set; } // integer

        // sys_RoleMenu_RoleId_fkey
        [Association(ThisKey = "RoleId", OtherKey = "Id", CanBeNull = false)]
        public sys_Role sys_Role { get; set; }

        // sys_RoleMenu_MenuId_fkey
        [Association(ThisKey = "MenuId", OtherKey = "Id", CanBeNull = false)]
        public sys_Menu sys_Menu { get; set; }
    }

    [TableName(Owner = "public", Name = "sys_RolePermission")]
    public partial class sys_RolePermission
    {
        [PrimaryKey(1)]
        public Int32 RoleId { get; set; } // integer
        [PrimaryKey(2)]
        public Int32 PermissionId { get; set; } // integer

        // sys_RolePermission_RoleId_fkey
        [Association(ThisKey = "RoleId", OtherKey = "Id", CanBeNull = false)]
        public sys_Role sys_Role { get; set; }

        // sys_RolePermission_PermissionId_fkey
        [Association(ThisKey = "PermissionId", OtherKey = "Id", CanBeNull = false)]
        public sys_Permission sys_Permission { get; set; }
    }
    #endregion
}